home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 2002 November / SGI Freeware 2002 November - Disc 1.iso / dist / fw_apache2.idb / usr / freeware / apache2 / include / apr_getopt.h.z / apr_getopt.h
C/C++ Source or Header  |  2002-07-08  |  8KB  |  193 lines

  1. /* ====================================================================
  2.  * The Apache Software License, Version 1.1
  3.  *
  4.  * Copyright (c) 2000-2002 The Apache Software Foundation.  All rights
  5.  * reserved.
  6.  *
  7.  * Redistribution and use in source and binary forms, with or without
  8.  * modification, are permitted provided that the following conditions
  9.  * are met:
  10.  *
  11.  * 1. Redistributions of source code must retain the above copyright
  12.  *    notice, this list of conditions and the following disclaimer.
  13.  *
  14.  * 2. Redistributions in binary form must reproduce the above copyright
  15.  *    notice, this list of conditions and the following disclaimer in
  16.  *    the documentation and/or other materials provided with the
  17.  *    distribution.
  18.  *
  19.  * 3. The end-user documentation included with the redistribution,
  20.  *    if any, must include the following acknowledgment:
  21.  *       "This product includes software developed by the
  22.  *        Apache Software Foundation (http://www.apache.org/)."
  23.  *    Alternately, this acknowledgment may appear in the software itself,
  24.  *    if and wherever such third-party acknowledgments normally appear.
  25.  *
  26.  * 4. The names "Apache" and "Apache Software Foundation" must
  27.  *    not be used to endorse or promote products derived from this
  28.  *    software without prior written permission. For written
  29.  *    permission, please contact apache@apache.org.
  30.  *
  31.  * 5. Products derived from this software may not be called "Apache",
  32.  *    nor may "Apache" appear in their name, without prior written
  33.  *    permission of the Apache Software Foundation.
  34.  *
  35.  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
  36.  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  37.  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  38.  * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
  39.  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  40.  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  41.  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  42.  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  43.  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  44.  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  45.  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  46.  * SUCH DAMAGE.
  47.  * ====================================================================
  48.  *
  49.  * This software consists of voluntary contributions made by many
  50.  * individuals on behalf of the Apache Software Foundation.  For more
  51.  * information on the Apache Software Foundation, please see
  52.  * <http://www.apache.org/>.
  53.  */
  54.  
  55. #ifndef APR_GETOPT_H
  56. #define APR_GETOPT_H
  57.  
  58. #include "apr_pools.h"
  59.  
  60. #ifdef __cplusplus
  61. extern "C" {
  62. #endif /* __cplusplus */
  63.  
  64. /**
  65.  * @file apr_getopt.h
  66.  * @brief APR Command Arguments (getopt)
  67.  */
  68. /**
  69.  * @defgroup APR_getopt Command Argument Parsing
  70.  * @ingroup APR
  71.  * @{
  72.  */
  73.  
  74. /** 
  75.  * defintion of a error function 
  76.  */
  77. typedef void (apr_getopt_err_fn_t)(void *arg, const char *err, ...);
  78.  
  79. typedef struct apr_getopt_t apr_getopt_t;
  80. /**
  81.  * Structure to store command line argument information.
  82.  */ 
  83. struct apr_getopt_t {
  84.     /** context for processing */
  85.     apr_pool_t *cont;
  86.     /** function to print error message (NULL == no messages) */
  87.     apr_getopt_err_fn_t *errfn;
  88.     /** user defined first arg to pass to error message  */
  89.     void *errarg;
  90.     /** index into parent argv vector */
  91.     int ind;
  92.     /** character checked for validity */
  93.     int opt;
  94.     /** reset getopt */
  95.     int reset;
  96.     /** count of arguments */
  97.     int argc;
  98.     /** array of pointers to arguments */
  99.     const char **argv;
  100.     /** argument associated with option */
  101.     char const* place;
  102.     /** set to nonzero to support interleaving options with regular args */
  103.     int interleave;
  104.     /** start of non-option arguments skipped for interleaving */
  105.     int skip_start;
  106.     /** end of non-option arguments skipped for interleaving */
  107.     int skip_end;
  108. };
  109.  
  110. typedef struct apr_getopt_option_t apr_getopt_option_t;
  111.  
  112. /**
  113.  * Structure used to describe options that getopt should search for.
  114.  */
  115. struct apr_getopt_option_t {
  116.     /** long option name, or NULL if option has no long name */
  117.     const char *name;
  118.     /** option letter, or a value greater than 255 if option has no letter */
  119.     int optch;
  120.     /** nonzero if option takes an argument */
  121.     int has_arg;
  122.     /** a description of the option */
  123.     const char *description;
  124. };
  125.  
  126. /**
  127.  * Initialize the arguments for parsing by apr_getopt().
  128.  * @param os   The options structure created for apr_getopt()
  129.  * @param cont The pool to operate on
  130.  * @param argc The number of arguments to parse
  131.  * @param argv The array of arguments to parse
  132.  * @remark Arguments 2 and 3 are most commonly argc and argv from main(argc, argv)
  133.  * The errfn is initialized to fprintf(stderr... but may be overridden.
  134.  */
  135. APR_DECLARE(apr_status_t) apr_getopt_init(apr_getopt_t **os, apr_pool_t *cont,
  136.                                       int argc, const char * const *argv);
  137.  
  138. /**
  139.  * Parse the options initialized by apr_getopt_init().
  140.  * @param os     The apr_opt_t structure returned by apr_getopt_init()
  141.  * @param opts   A string of characters that are acceptable options to the 
  142.  *               program.  Characters followed by ":" are required to have an 
  143.  *               option associated
  144.  * @param option_ch  The next option character parsed
  145.  * @param option_arg The argument following the option character:
  146.  * @return There are four potential status values on exit. They are:
  147.  * <PRE>
  148.  *             APR_EOF      --  No more options to parse
  149.  *             APR_BADCH    --  Found a bad option character
  150.  *             APR_BADARG   --  No argument followed @parameter:
  151.  *             APR_SUCCESS  --  The next option was found.
  152.  * </PRE>
  153.  */
  154. APR_DECLARE(apr_status_t) apr_getopt(apr_getopt_t *os, const char *opts, 
  155.                                      char *option_ch, const char **option_arg);
  156.  
  157. /**
  158.  * Parse the options initialized by apr_getopt_init(), accepting long
  159.  * options beginning with "--" in addition to single-character
  160.  * options beginning with "-".
  161.  * @param os     The apr_getopt_t structure created by apr_getopt_init()
  162.  * @param opts   A pointer to a list of apr_getopt_option_t structures, which
  163.  *               can be initialized with { "name", optch, has_args }.  has_args
  164.  *               is nonzero if the option requires an argument.  A structure
  165.  *               with an optch value of 0 terminates the list.
  166.  * @param option_ch  Receives the value of "optch" from the apr_getopt_option_t
  167.  *                   structure corresponding to the next option matched.
  168.  * @param option_arg Receives the argument following the option, if any.
  169.  * @return There are four potential status values on exit.   They are:
  170.  * <PRE>
  171.  *             APR_EOF      --  No more options to parse
  172.  *             APR_BADCH    --  Found a bad option character
  173.  *             APR_BADARG   --  No argument followed @parameter:
  174.  *             APR_SUCCESS  --  The next option was found.
  175.  * </PRE>
  176.  * When APR_SUCCESS is returned, os->ind gives the index of the first
  177.  * non-option argument.  On error, a message will be printed to stdout unless
  178.  * os->err is set to 0.  If os->interleave is set to nonzero, options can come
  179.  * after arguments, and os->argv will be permuted to leave non-option arguments
  180.  * at the end (the original argv is unaffected).
  181.  */
  182. APR_DECLARE(apr_status_t) apr_getopt_long(apr_getopt_t *os,
  183.                       const apr_getopt_option_t *opts,
  184.                       int *option_ch,
  185.                                           const char **option_arg);
  186. /** @} */
  187.  
  188. #ifdef __cplusplus
  189. }
  190. #endif
  191.  
  192. #endif  /* ! APR_GETOPT_H */
  193.